import React, { Component } from 'react'
import { connect } from 'react-redux'

// connect 是一个生成高阶组件的函数
// connect() 返回一个高阶组件

const mapStateToProps = state => ({
  count: state.count
})

const mapDispatchToProps = dispatch => ({
  add() {
    dispatch({
      type: 'add'
    })
  }
})

@connect(mapStateToProps, mapDispatchToProps)
class App extends Component {
  render() {
    return (
      <div>
        {this.props.count}
        <button onClick={this.props.add}>+</button>
      </div>
    );
  }
}

export default App;